<!--
作者：T先森
QQ：1379146389
官网：doic.cn
本免费开源使用，请遵循开源协议，勿用于商业转售、闭源改造。二次开发需保留版权声明与开源标识，衍生代码同样开源。有疑问可联系作者反馈。 
-->

<!DOCTYPE html>
<html>

<head>
    <title>爱看 - 图床云</title>
    <link rel="icon" href="https://doic.cn/d/p/108.png" type="image/x-icon">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.85, maximum-scale=1.0, user-scalable=0">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        body {
            font-family: 'Montserrat', sans-serif;
            background-color: #e6f7ff; /* 新的背景色，浅蓝色 */
            color: #333; /* 主要文字颜色为深色 */
            margin: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

       .container {
            padding: 20px;
            border-radius: 8px;
        }

        h1 {
            color: #007acc; /* 标题颜色为深蓝色 */
            text-align: center;
            font-size: 2.5em;
            margin-bottom: 30px;
            letter-spacing: 2px;
        }        p {
            font-size: 1.2em;
            color: #666; /* 段落文字颜色为灰色 */
            max-width: 800px;
            text-align: center;
            line-height: 1.8;
        }


       .upload-success {
            text-align: center;
        }

       .upload-success button {
            background-color: #ff9900; /* 按钮颜色为橙色 */
            color: #fff;
            border: none;
            padding: 15px 30px;
            font-size: 1.2em;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            margin: 10px;
        }

       .upload-success button:hover {
            background-color: #e68a00; /* 按钮悬停颜色为深橙色 */
        }

       .file-preview-container {
            text-align: center;
        }

       .file-preview-container img,
       .file-preview-container video {
            max-width: 100%;
            max-height: 300px;
            margin-top: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }

       .file-link {
            color: #007acc; /* 链接颜色为深蓝色 */
            font-size: 1.2em;
            text-decoration: none;
            display: block;
            margin-top: 20px;
        }

       .info-text {
            text-align: center;
            margin-top: 30px;
            font-size: 12px;
            color: #666; /* 信息文本颜色为灰色 */
            position: fixed;
            bottom: 15px;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>AiKan TyunOS</h1>
        <p>畅享高效的图床服务，轻松管理图像与视频资源。</p>
        <div class="upload-success">
            <div>
                <button onclick="window.location.href='./'" id="file-input-label">
                    <i class="fas fa-redo-alt"></i> 点击返回
                </button>
                <button onclick="copyLink()">
                    <i class="fas fa-copy"></i> 复制链接
                </button>
            </div>
            <br>
            <?php
            $targetDir = "p/";
            $allowTypes = array('jpg','JPG','PNG', 'png', 'jpeg', 'gif', 'mp4', 'mov', 'avi');

            // 检查目标目录是否存在，如果不存在则创建
            if (!is_dir($targetDir)) {
                mkdir($targetDir, 0755, true);
            }

            if (!empty($_FILES['files']['name'][0])) {
                $files = $_FILES['files'];
                $links = []; // 存储生成的链接
                foreach ($files['name'] as $key => $val) {
                    $fileType = pathinfo($val, PATHINFO_EXTENSION);
                    if (in_array($fileType, $allowTypes)) {
                        // 获取上传时间作为文件名基础
                        $uploadTime = date('yn');
                        $fileIndex = 1;
                        $newFileName = $uploadTime. "$fileIndex";
         

                        // 如果是图片文件，改为.jpg 格式
                        if (in_array($fileType, array('jpg', 'jpeg', 'png', 'gif'))) {
                            $newFileName.= ".jpg";
                        } else {
                            $newFileName.= ".$fileType";
                        }

                        // 处理重复文件名
                        $newFilePath = $targetDir. $newFileName;
                        while (file_exists($newFilePath)) {
                            $fileIndex++;
                            $newFileName = $uploadTime. "$fileIndex";
                            if (in_array($fileType, array('jpg', 'jpeg', 'png', 'gif'))) {
                                $newFileName.= ".jpg";
                            } else {
                                $newFileName.= ".$fileType";
                            }
                            $newFilePath = $targetDir. $newFileName;
                        }

                        if (move_uploaded_file($files['tmp_name'][$key], $newFilePath)) {
                            // 动态生成链接
                            $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'? 'https://' : 'http://';
                            $domain = $_SERVER['HTTP_HOST'];
                            $path = rtrim(dirname($_SERVER['REQUEST_URI']), '/\\');
                            $url = $protocol. $domain. $path. "/$newFilePath";

                            echo "<div class='file-preview-container'>";
                            
                            if (in_array($fileType, array('mp4', 'mov', 'avi'))) {
                                echo "<video controls><source src='$newFilePath' type='video/$fileType'></video>";
                                } else {
                                    // 将图片用 <a> 标签包裹，设置 href 属性为图片链接
                                    echo "<a href='$url' target='_blank'><img src='$newFilePath'></a>";
                                    
                                }
                            echo "</div>";
                            echo "<div style='position: relative; display: inline-block;'>";
                            echo "<span class='file-link' id='fileUrl$key'>$url</span>";
                            echo "</div>";

                            $links[] = $url; // 将链接添加到数组
                        } else {
                            echo "文件上传失败: $val";
                        }
                    } else {
                        echo "不支持的文件类型: $val";
                    }
                }
            } else {
                echo "请先选择文件再上传。";
            }
           ?>
        </div>
    </div>
    <div class="info-text">
        <a href="http://doic.cn" style="color: #666; text-decoration: none;">© 2023 TyunOS All Rights Reserved.</a>
        <a href="https://admin.qidian.qq.com/static_proxy/b2b-qq/wpa-link/index.html#/person?uin=1379146389"
           style="color: #666; text-decoration: none;">联系管理员</a>
    </div>
    <script>
        function copyLink() {
            // 获取所有文件链接元素
            var fileLinks = document.getElementsByClassName('file-link');
            var urls = '';
            for (var i = 0; i < fileLinks.length; i++) {
                urls += fileLinks[i].textContent + '\n';
            }
            var textArea = document.createElement("textarea");
            textArea.value = urls;
            document.body.appendChild(textArea);
            textArea.select();
            textArea.setSelectionRange(0, 99999);
            document.execCommand('copy');
            document.body.removeChild(textArea);
            alert('链接已复制，请返回粘贴！');
        }
    </script>
</body>

</html>



<!--统计代码请勿删除--><script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?82d3850e9cffef7bdfde3db3e6e4b978";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({id:"KFunBsxDl2bThYnS",ck:"KFunBsxDl2bThYnS"})</script>